function isElementAtPositionBiggerThanItsNeighbours(array, position)
{
    if (position === 0 || position === array.length - 1)
    {
        console.log('This position does not have two neighbours');
        return false;
    }
    else if (array[position] > array[position - 1] && array[position] > array[position + 1])
    {
        return true;
    }
    else
    {
        return false;
    }
}

function indexOfTheFirstBiggerNeighbour(array)
{
    for (var i = 1; i < array.length - 1; i++)
    {
        if (isElementAtPositionBiggerThanItsNeighbours(array, i) === true)
        {
            return i;
        }
    }

    return -1;
}

console.log(indexOfTheFirstBiggerNeighbour([3,1,4,2]));
console.log(indexOfTheFirstBiggerNeighbour([3,1,0,2]));